home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 42.1 KB | 1,474 lines | [TEXT/MPS ] |
- // UEditionDocument.cp
- // Copyright © 1984-1991 by Apple Computer Inc. All rights reserved.
-
- #ifndef __UEDITIONDOCUMENT__
- #include <UEditionDocument.h>
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __UFILE__
- #include <UFile.h>
- #endif
-
- #ifndef __USECTION__
- #include <USection.h>
- #endif
-
- #ifndef __UWINDOW__
- #include <UWindow.h>
- #endif
-
- #ifndef __UFILEHANDLER__
- #include <UFileHandler.h>
- #endif
-
- #ifndef __UAPPLICATION__
- #include <UApplication.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UERRORMGR__
- #include <UErrorMgr.h>
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include <UMacAppGlobals.h>
- #endif
-
- #ifndef __UMEMORY__
- #include <UMemory.h>
- #endif
-
- #ifndef __UMENUMGR__
- #include <UMenuMgr.h>
- #endif
-
- const unsigned long kEditionDocRsrcType = 'EdSt';// rsrc type for Edition Doc private rsrc
- const short kEditionDocRsrcID = 301; // rsrc id for Edition Doc private rsrc
-
- typedef struct EditionDocSettings
- { // used for saving settings in a resource
- Boolean showSectionBorders;
- Boolean stopAllEditions;
- } *EditionDocSettingsPtr, ** EditionDocSettingsHandle;
-
- typedef pascal void (*DoToSectionType) (TSection* item, void* staticLink);
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
- ArrayIndex itsLowBound,
- ArrayIndex itsHighBound,
- Boolean itsForward) :
- CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsLowBound, itsHighBound, itsForward)
-
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
- Boolean itsForward) :
- CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsForward)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CSectionIterator::CSectionIterator(TEditionDocument* itsDocument) :
- CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL)
- {
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- TSection* CSectionIterator::CurrentSection(void)
- {
- return (TSection*)this->CurrentObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- TSection* CSectionIterator::FirstSection(void)
- {
- return (TSection*)this->FirstObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- TSection* CSectionIterator::NextSection(void)
- {
- return (TSection*)this->NextObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAInit
-
- pascal void InitUEditionDocument(void)
-
- {
- /* if application NEEDS the edition mgr,
- * then fail out if it can't load,
- * else if system HAS the edition mgr,
- * then continue if we can't get it (and set gConfiguration accordingly). */
-
- if (qNeedsEditionMgr)
- FailOSErr(InitEditionPack());
- else if (gConfiguration.hasEditionMgr)
- {
- OSErr err = InitEditionPack();
- if (err != noErr)
- if (err == editionMgrInitErr)
- gConfiguration.hasEditionMgr = FALSE;// could not load edition pack
- else
- FailOSErr(err);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TEditionDocument::Initialize(void) // override
-
- {
- inherited::Initialize();
-
- fSectionList = NULL;
- fStopAllEditions = FALSE;
- fShowSectionBorders = TRUE;
- fNextEditionNumber = 1;
- fNewPublishers = FALSE;
- fEditionCreator = '????';
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- pascal void TEditionDocument::IEditionDocument(TFile* itsFile,
- const OSType itsFileType,
- const OSType itsCreator,
- const OSType itsScrapType,
- Boolean usesDataFork,
- Boolean usesRsrcFork,
- Boolean keepsDataOpen,
- Boolean keepsRsrcOpen,
- const OSType editionCreator)
-
- {
- this->IFileBasedDocument(itsFile, itsFileType, itsCreator, itsScrapType, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
-
- fEditionCreator = editionCreator;
-
- fSectionList = NewList(); // !!! needs failure handler
- if (qDebug)
- fSectionList->SetEltType("TSection"); // takes MAName
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TEditionDocument::Free(void) // override
-
- {
- fSectionList = (TList *)FreeListIfObject(fSectionList);
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TEditionDocument::FreeData(void) // override
-
- {
- fSectionList->FreeAll();
-
- inherited::FreeData();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- pascal Boolean TEditionDocument::CanPublishSelection(void)
-
- {
- // ask the target view if it can publish the selection
- return (FALSE);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- pascal Boolean TEditionDocument::CanSubscribe(void)
-
- {
- // ask the target view if it can subscribe
- return (FALSE);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- pascal void TEditionDocument::DoWrite(TFile* aFile,
- Boolean makingCopy)// override
-
- {
- CSectionIterator iter(this);
-
- // 1. Tell all canceled sections to delete themselves: publishers delete their container file
- // and all section objects remove their section rsrcs from the rsrc fork if any. The routine also
- // removes a section from the document's list of sections and frees the section.
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->fCanceled)
- {
- aSection->Delete();
- this->RemoveSection(aSection);
- aSection->Free();
- }
-
- // 2. write out (as a resource) fStopAllEditions and fShowSectionBorders
- this->DoWriteSettings(aFile);
-
- // 3. tell each section to write itself out
- for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- aSection->DoWrite(aFile, makingCopy);
-
- // 4. clear the new publishers flag
- fNewPublishers = FALSE;
-
- inherited::DoWrite(aFile, makingCopy);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- pascal void TEditionDocument::DoWriteSettings(TFile*)
-
- {
- EditionDocSettingsHandle h = (EditionDocSettingsHandle)NewPermHandle(sizeof(EditionDocSettings));
-
- (*h)->showSectionBorders = fShowSectionBorders;
- (*h)->stopAllEditions = fStopAllEditions;
-
- AddResource((Handle)h, kEditionDocRsrcType, kEditionDocRsrcID, "Edition Doc Settings");
- FailResError();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TEditionDocument::DoRead(TFile* aFile,
- Boolean forPrinting)// override
-
- {
- // 1. read in (from a resource) fStopAllEditions and fShowSectionBorders
- this->DoReadSettings(aFile);
-
- // 2. create the section objects and tell each section to read itself in
- for (short i = 1; i <= Count1Resources(rSectionType); ++i)
- {
- short theID;
- Handle h;
-
- h = Get1IndResource(rSectionType, i); // get the resource handle
- FailNIL((void*)h);
- theID = (short)(*((SectionHandle)h))->sectionID;
- switch ((*((SectionHandle)h))->kind)
- {
- case stPublisher:
- this->DoReadPublisher(aFile, theID); // !!! pass in a resource stream
- break;
- case stSubscriber:
- this->DoReadSubscriber(aFile, theID); // !!! pass in a resource stream
- break;
- default:
- if (qDebug)
- ProgramBreak("SectionHandle appears to be corrupt");
- break;
- }
- }
-
- // 3. read in the rest of the document's data
- inherited::DoRead(aFile, forPrinting);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TEditionDocument::DoReadSettings(TFile*)
-
- {
- Handle h = Get1Resource(kEditionDocRsrcType, kEditionDocRsrcID);
- FailNIL(h);
- fShowSectionBorders = (*((EditionDocSettingsHandle)h))->showSectionBorders;
- fStopAllEditions = (*((EditionDocSettingsHandle)h))->stopAllEditions;
- ReleaseResource(h);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TEditionDocument::DoReadPublisher(TFile* aFile,
- short theID)
-
- {
- TPublisher * aPublisher = this->DoMakePublisher(NULL, NULL, theID);
- aPublisher->DoRead(aFile);
- this->AddSection(aPublisher);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- pascal void TEditionDocument::DoReadSubscriber(TFile* aFile,
- short theID)
-
- {
- TSubscriber * aSubscriber = this->DoMakeSubscriber(NULL, NULL, theID);
- aSubscriber->DoRead(aFile);
- this->AddSection(aSubscriber);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- pascal void TEditionDocument::DoMenuCommand(CmdNumber aCmdNumber)// override
-
- {
- switch (aCmdNumber)
- {
- case cCreatePublisher:
- this->DoNewPublisher();
- break;
- case cSubscribeTo:
- this->DoNewSubscriber();
- break;
- case cOptions:
- this->DoSectionOptions();
- break;
- case cBorders:
- {
- TSectionBorderCmd * aSectionBorderCmd = new TSectionBorderCmd;
- aSectionBorderCmd->ISectionBorderCmd(cBorders, this);
- this->PostCommand(aSectionBorderCmd);
- break;
- }
- case cStopAllEditions:
- {
- TStopAllEditionsCmd * aStopAllEditionsCmd = new TStopAllEditionsCmd;
- aStopAllEditionsCmd->IStopAllEditionsCmd(cStopAllEditions, this);
- this->PostCommand(aStopAllEditionsCmd);
- break;
- }
- default:
- inherited::DoMenuCommand(aCmdNumber);
- break;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoSectionOptions(void)
-
- {
- TSection * aSection = this->GetSelectedSection();
- if (aSection != NULL)
- {
- if (aSection->GetSectionType() == stPublisher)
- this->DoPublisherOptions((TPublisher *)aSection);
- else if (aSection->GetSectionType() == stSubscriber)
- this->DoSubscriberOptions((TSubscriber *)aSection);
- else if (qDebug)
- ProgramBreak("what kind of section is it anyway?");
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TEditionDocument::Close(void) // override
-
- {
- /* preflight the Close for the case in which the document's DATA is unchanged (the change
- count is 0) but there are new publishers in the document */
- if ((this->GetChangeCount() == 0) && fNewPublishers)
- {
- TCommand * lastCommand = NULL;
- short poseResult = this->PoseNewPublishersAlert();
- if (poseResult == cancel)
- Failure(noErr, msgCancelled);
-
- lastCommand = this->GetLastCommand();
- if ((lastCommand != NULL) && (lastCommand->fChangedObject == this))
- this->CommitLastCommand();
-
- switch (poseResult)
- {
- case kYesButton:
- this->SaveDocument(cClose); // Will fail if unable to save
- break;
- case kNoButton:
- this->Abandon();
- break;
- }
- }
-
- inherited::Close();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- struct PoseItInfo
- {
- public:
- PoseItInfo(short itsResult,
- short itsAlertID) :
- result(itsResult),
- alertID(itsAlertID)
- {
- }
-
- short result;
- short alertID;
- };
-
-
- pascal void PoseIt(void* staticLink)
-
- {
- short result = MacAppAlert(((PoseItInfo *)staticLink)->alertID, NULL);
- ((PoseItInfo *)staticLink)->result = result;
- }
-
-
- pascal short TEditionDocument::PoseNewPublishersAlert(void)
-
- {
- short idx;
- Str255 name;
- Str255 reason;
- PoseItInfo info(0, phNewPublisherAlert);
-
- if (gApplication->fAppDone)
- idx = bzQuitting;
- else
- idx = bzClosing;
-
- GetIndString(reason, kIDBuzzString, idx);
- name = fTitle; // ParamText can compact heap
- ParamText(name, reason, "", "");
- WithApplicationResFileDo(PoseIt, &info);
- return info.result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal short TEditionDocument::PoseMultPublishersAlert(TSection* aSection)
-
- {
- Str255 name;
- PoseItInfo info(0, phMultPublisherWrn);
-
- aSection->GetEditionName(name);
- ParamText(name, "", "", "");
- WithApplicationResFileDo(PoseIt, &info);
- return info.result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal short TEditionDocument::PoseSavingMultPublishersAlert(TSection* aSection)
-
- {
- Str255 name;
- Str255 docName;
- PoseItInfo info(0, phSavingMultPublisherWrn);
-
- aSection->GetEditionName(name);
- docName = fTitle; // ParamText can compact heap
- ParamText(name, docName, "", "");
- WithApplicationResFileDo(PoseIt, &info);
- return info.result;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- pascal void TEditionDocument::Abandon(void) // override
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stPublisher)
- {
- // if publisher is *new* and it hasn't been saved yet,
- // delete the edition container file
- if (((TPublisher*)aSection)->fNewSection)
- ((TPublisher*)aSection)->DeleteEditionFile();
- }
-
- inherited::Abandon();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- pascal void TEditionDocument::DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes)
- {
- inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
-
- rsrcForkBytes = rsrcForkBytes + sizeof(EditionDocSettings);
-
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- aSection->DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoNewPublisher(void)
-
- {
- OSErr err;
- NewPublisherReply reply;
- TDesignator * itsDesignator;
- short newSectionID;
- SectionHandle sectionH;
- TPublisher * aPublisher;
- TFileHandler * aFileHandler;
- FSSpec aFSSpec;
- FSSpecPtr aFSSpecPtr;
-
- // set up the reply record
- err = GetLastEditionContainerUsed(reply.container);
- if ((err != noErr) && (err != fnfErr)) // allow fnfErr
- FailOSErr(err);
- this->GetNextEditionName(reply.container.theFile.name);
- reply.usePart = FALSE; // always set this to FALSE
-
- // create the preview
- itsDesignator = this->GetUserSelection();
- FailNIL(itsDesignator); // ??? allow non-designated publishers
-
- this->DoMakePreview(itsDesignator, reply.previewFormat, reply.preview);
-
- this->DoNewPublisherDialog(reply); // query the user
-
- // dispose of the preview
- if (reply.previewFormat == 'PICT')
- reply.preview = (Handle)DisposeIfPicHandle((PicHandle) reply.preview);
- else if (reply.previewFormat == 'TEXT')
- reply.preview = DisposeIfHandle(reply.preview);
-
- if (!reply.canceled)
- {
- if (!reply.replacing)
- FailOSErr(CreateEditionContainerFile(reply.container.theFile, this->GetEditionCreatorSignature(), reply.container.theFileScript));
- newSectionID = this->GetUniqueSectRsrcID();
-
- aFSSpecPtr = NULL; // can pass in NULL to NewSection
- aFileHandler = this->GetFileHandler();
- if ((aFileHandler != NULL) && (aFileHandler->FileExists()))
- {
- aFileHandler->fFile->GetFileSpec(aFSSpec);
- aFSSpecPtr = &aFSSpec;
- }
- // NewSection calls RegisterSection for us
- err = NewSection(reply.container, aFSSpecPtr, stPublisher, newSectionID, pumOnSave, sectionH);
- if ((err != noErr) && (err != multiplePublisherWrn) && (err != notThePublisherWrn))
- FailOSErr(err);
-
- // Create the publisher object and publish it to disk
- if (itsDesignator != NULL)
- itsDesignator = (TDesignator *)itsDesignator->Clone();// publisher owns its designator
- aPublisher = this->DoMakePublisher(itsDesignator, sectionH, newSectionID);
- this->AddSection(aPublisher);
- aPublisher->Publish();
-
- // let the edition document know that there is a new publisher
- fNewPublishers = TRUE;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoMakePreview(TDesignator* aDesignator,
- FormatType& previewFormat,
- Handle& preview)
-
- {
- preview = NULL;
- previewFormat = this->GetPublishPreference();
- if ((previewFormat == 'TEXT') || (previewFormat == 'PICT'))
- {
- FailInfo fi;
- THandleStream* aHandleStream = NULL;
- VOLATILE(aHandleStream); // needed in failure handler
-
- preview = NewPermHandle(0);
- if (fi.Try())
- {
- aHandleStream = new THandleStream;
- aHandleStream->IHandleStream(preview, 6);
- this->DoWriteData(previewFormat, aDesignator, aHandleStream);
- aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
- fi.Success();
- }
- else // Recover
- {
- preview = DisposeIfHandle(preview);
- aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
- fi.ReSignal();
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal OSType TEditionDocument::GetEditionCreatorSignature(void)
-
- {
- return fEditionCreator;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal FormatType TEditionDocument::GetPublishPreference(void)
-
- {
- return ((long)'TEXT'); /* by default, prefer to publish 'TEXT' over 'PICT' */
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal TPublisher* TEditionDocument::DoMakePublisher(TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsSectionID)
-
- {
- TPublisher * aPublisher = new TPublisher; // create a TPublisher object
- aPublisher->IPublisher(this, itsDesignator, itsSectionHandle, itsSectionID);
- return aPublisher;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoNewPublisherDialog(NewPublisherReply& reply)
-
- {
- // override this method if you decide to use the NewPublisherExpDialog instead
- FailOSErr(NewPublisherDialog(reply));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoNewSubscriber(void)
-
- {
- OSErr err;
- NewSubscriberReply reply;
- short newSectionID;
- TFileHandler * aFileHandler;
- FSSpec aFSSpec;
- FSSpecPtr aFSSpecPtr;
- SectionHandle sectionH;
- TSubscriber * aSubscriber;
- TDesignator * aDesignator;
-
- err = GetLastEditionContainerUsed(reply.container);// fill in the reply
- if ((err != noErr) && (err != fnfErr)) // allow fnfErr
- FailOSErr(err);
- reply.formatsMask = this->GetSubscriberFormatsMask();// set up the formatsMask
- this->DoNewSubscriberDialog(reply);
- if (!reply.canceled)
- {
- newSectionID = this->GetUniqueSectRsrcID();
- // create a new section handle
- aFSSpecPtr = NULL;
- aFileHandler = this->GetFileHandler();
- if ((aFileHandler != NULL) && (aFileHandler->FileExists()))
- {
- aFileHandler->fFile->GetFileSpec(aFSSpec);
- aFSSpecPtr = &aFSSpec;
- }
- FailOSErr(NewSection(reply.container, aFSSpecPtr, stSubscriber, newSectionID, sumAutomatic, sectionH));
- // NewSection calls RegisterSection for us
-
- // create a TDesignator for the TSubscriber object
- aDesignator = this->GetUserSelection();
- if (aDesignator != NULL)
- aDesignator = (TDesignator *)aDesignator->Clone();// the subscriber owns the designator
-
- // create a TSubscriber object and add it to our list of sections
- aSubscriber = this->DoMakeSubscriber(aDesignator, sectionH, newSectionID);
- this->AddSection(aSubscriber);
- // aSubscriber->Subscribe(); Ed Mgr will send us a SectionEvent telling us to read the section
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal TSubscriber* TEditionDocument::DoMakeSubscriber(TDesignator* itsDesignator,
- SectionHandle itsSectionHandle,
- short itsSectionID)
-
- {
- // create and return a TSubscriber object
- TSubscriber * aSubscriber = new TSubscriber;
- aSubscriber->ISubscriber(this, itsDesignator, itsSectionHandle, itsSectionID);
- return aSubscriber;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoNewSubscriberDialog(NewSubscriberReply& reply)
-
- {
- // override this method if you decide to use the NewSubscriberExpDialog instead
- FailOSErr(NewSubscriberDialog(reply)); // pose the new subscriber dialog
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoPublisherOptions(TPublisher* aPublisher)
-
- {
- SectionOptionsReply reply;
-
- reply.sectionH = aPublisher->fSectionHandle;
- this->DoPublisherOptionsDialog(reply);
- if (!reply.canceled)
- {
- if (reply.changed)
- aPublisher->MarkDirty();
-
- if (reply.action == sectionWriteMsgID)
- aPublisher->Publish();
- else if (reply.action == sectionCancelMsgID)
- {
- TCancelPublisherCmd * aCancelPublisherCmd = new TCancelPublisherCmd;
- aCancelPublisherCmd->ICancelPublisherCmd(cCancelPublisher, this, aPublisher);
- this->PostCommand(aCancelPublisherCmd);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoPublisherOptionsDialog(SectionOptionsReply& reply)
-
- {
- // override this method if you decide to use the SectionOptionsExpDialog instead
- FailOSErr(SectionOptionsDialog(reply)); // should it call SectionOptionsExpDialog always???
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoSubscriberOptions(TSubscriber* aSubscriber)
-
- {
- SectionOptionsReply reply;
-
- reply.sectionH = aSubscriber->fSectionHandle;
- this->DoSubscriberOptionsDialog(reply);
- if (!reply.canceled)
- {
- if (reply.changed)
- aSubscriber->MarkDirty();
-
- if (reply.action == sectionReadMsgID)
- aSubscriber->Subscribe();
- else if (reply.action == 'goto')
- aSubscriber->OpenPublisher();
- else if (reply.action == sectionCancelMsgID)
- {
- TCancelSubscriberCmd * aCancelSubscriberCmd = new TCancelSubscriberCmd;
- aCancelSubscriberCmd->ICancelSubscriberCmd(cCancelSubscriber, this, NULL, aSubscriber);
- this->PostCommand(aCancelSubscriberCmd);
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::DoSubscriberOptionsDialog(SectionOptionsReply& reply)
-
- {
- // override this method if you decide to use the SectionOptionsExpDialog instead
- FailOSErr(SectionOptionsDialog(reply)); // should it call SectionOptionsExpDialog always???
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- pascal void TEditionDocument::DoSetupMenus(void)// override
-
- {
- inherited::DoSetupMenus();
-
- if (gConfiguration.hasEditionMgr) /* *always* test to ensure that the Edition
- Mgr was initialized */
- {
- if (fNewPublishers) // there are new publishers!
- {
- Enable(cSave, TRUE);
- Enable(cRevert, TRUE);
- }
-
- Enable(cCreatePublisher, this->CanPublishSelection());
- Enable(cSubscribeTo, this->CanSubscribe());
-
- TSection * aSection = this->GetSelectedSection();
- if (aSection != NULL)
- {
- Enable(cOptions, TRUE);
- if (aSection->GetSectionType() == stPublisher)
- SetIndCmdName(cOptions, kIDBuzzString, bzPublisherOptions);
- else if (aSection->GetSectionType() == stSubscriber)
- SetIndCmdName(cOptions, kIDBuzzString, bzSubscriberOptions);
- else if (qDebug)
- ProgramBreak("what kind of section is it anyway?");
- }
-
- Enable(cBorders, TRUE);
- SetMenuState(cBorders, kIDBuzzString, bzShowBorders, bzHideBorders, fShowSectionBorders);
-
- EnableCheck(cStopAllEditions, TRUE, fStopAllEditions);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::GetNextEditionName(Str63& editionName)
-
- {
- short preInsert;
- short constChars;
- Str255 name(""), numStr("");
-
- editionName = "";
- GetIndString(name, kIDBuzzString, bzUntitled);
- if (ParseTitleTemplate(name, preInsert, constChars))
- {
- NumToString(fNextEditionNumber, numStr);
- if (SubstituteInTitle(name, numStr, preInsert, constChars))
- ++fNextEditionNumber;
- }
- CopyStr255(name, (Ptr) & editionName);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal SignedByte TEditionDocument::GetSubscriberFormatsMask(void)
-
- {
- /* return a mask corresponding to the edition format type to display within the subscriber
- dialog box as follows:
- GetSubscriberFormatsMask = [kPICTformatMask +] [kTextformatMask +] [ksndFormatMask] */
-
- return (kTEXTformatMask); // default return value
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- const short kFirstRsrcID = 1000;
- const short kLastRsrcID = 32767;
- const short kBitsInArray = kLastRsrcID - kFirstRsrcID;
-
- pascal short TEditionDocument::GetUniqueSectRsrcID(void)
- {
- short counter = 0;
- Size arraySize = (kBitsInArray / sizeof(Byte)) + 1;
- Ptr aPtr = NewPermPtr(arraySize);
- Boolean foundNewID;
-
- BlockSet(aPtr, arraySize, 0x00); // zero it out
-
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- {
- short itsRsrcID = aSection->fRsrcID;
-
- if (itsRsrcID >= kFirstRsrcID)
- BitSet(aPtr, itsRsrcID - kFirstRsrcID);
- else
- {
- if (qDebug)
- ProgramBreak("problem with section rsrc id");
- }
- }
-
- while (BitTst(aPtr, counter) && (counter < kBitsInArray))
- ++counter;
-
- foundNewID =!BitTst(aPtr, counter); // see if we got a new rsrc id
-
- aPtr = DisposeIfPtr(aPtr); // dispose of the array
-
- if (!foundNewID)
- Failure(minErr, 0);
-
- return (counter + kFirstRsrcID); // return the new sect rsrc id
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- pascal Boolean TEditionDocument::IsBorderShown(TSection* aSection)
-
- {
- return (fShowSectionBorders || this->IsSectionSelected(aSection));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal Boolean TEditionDocument::IsSectionSelected(TSection* aSection)
-
- {
- TDesignator * userSelection;
-
- if ((aSection != NULL) && (aSection->fDesignator != NULL))
- {
- userSelection = this->GetUserSelection();
- if (userSelection != NULL)
- return (userSelection->IsContained(aSection->fDesignator) != kNotContained);
- else
- return (FALSE);
- }
- else
- return (FALSE);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal Boolean TEditionDocument::IsAnySectionDirty(void)
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->IsDirty())
- return TRUE;
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::AddSection(TSection* aSection)
-
- {
- // Protect against double installation
- if (fSectionList)
- {
- if (fSectionList->GetIdentityItemNo(aSection) == 0)// doesn't already exist in list
- fSectionList->Insert(aSection);
- }
- else if (qDebug)
- ProgramBreak("fSectionList is NULL");
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::RemoveSection(TSection* aSection)
-
- {
- if (fSectionList)
- fSectionList->Delete(aSection);
- else if (qDebug)
- ProgramBreak("fSectionList is NULL");
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::CancelSection(TSection* aSection,
- Boolean cancel)
-
- {
- aSection->CancelSection(cancel);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::EachSectionDo(pascal void(* DoToSection)(TSection* aSection,
- void* staticLink),
- void* staticLink)
- {
- if (fSectionList)
- fSectionList->Each((DoToObjectType)DoToSection, staticLink);
- else if (qDebug)
- ProgramBreak("fSectionList is NULL");
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::EachPublisherDo(pascal void(* DoToPublisher)(TPublisher* aPublisher,
- void* staticLink),
- void* staticLink)
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stPublisher)
- DoToPublisher((TPublisher *)aSection, staticLink);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::EachCanceledSectionDo(pascal void(* DoToCanceledSection)(TSection* aSection,
- void* staticLink),
- void* staticLink)
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->fCanceled)
- DoToCanceledSection(aSection, staticLink);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::EachSubscriberDo(pascal void(* DoToSubscriber)(TSubscriber* aSubscriber,
- void* staticLink),
- void* staticLink)
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stSubscriber)
- DoToSubscriber((TSubscriber *)aSection, staticLink);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal TSection* TEditionDocument::FirstSectionThat(pascal Boolean(* TestSection)(TSection* aSection,
- void* staticLink),
- void* staticLink)
- {
- if (fSectionList)
- return (TSection *)(fSectionList->FirstThat((TestObjectType)TestSection, staticLink));
- else
- {
- if (qDebug)
- ProgramBreak("fSectionList is NULL");
- return (NULL);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal TSection* TEditionDocument::GetSectionObject(SectionHandle aSectionHandle)
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->fSectionHandle == aSectionHandle)
- return aSection;
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal TSection* TEditionDocument::GetSelectedSection(void)
- {
- return (NULL);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFields
-
- pascal void TEditionDocument::Fields(TObject* obj)
-
- {
- obj->DoToField("TEditionDocument", NULL, bClass);
- obj->DoToField("fSectionList", & fSectionList, bObject);
- obj->DoToField("fStopAllEditions", & fStopAllEditions, bBoolean);
- obj->DoToField("fShowSectionBorders", & fShowSectionBorders, bBoolean);
- obj->DoToField("fNextEditionNumber", & fNextEditionNumber, bInteger);
- obj->DoToField("fNewPublishers", & fNewPublishers, bBoolean);
- obj->DoToField("fEditionCreator", & fEditionCreator, bOSType);
-
- inherited::Fields(obj);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- pascal void TEditionDocument::SetSectionBorders(Boolean state,
- Boolean invalidate)
- {
- if (fShowSectionBorders != state)
- {
- fShowSectionBorders = state;
-
- /* !!! should probably:
- if (invalidate)
- this->EachSectionDo(InvalidateSection); this requires TSection.Invalidate
- */
-
- if (invalidate)
- {
- CWindowIterator iter(this);
-
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- aWindow->ForceRedraw();
- }
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- pascal void TEditionDocument::SetStopAllEditions(Boolean state)
- {
- if (fStopAllEditions != state)
- {
- fStopAllEditions = state;
- if (!state) // if turning "off" stop editions
- {
- CSectionIterator iter(this);
-
- for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
- if (aSection->GetSectionType() == stSubscriber)
- ((TSubscriber*)aSection)->SubscribeIfNewer();
- }
- }
- }
-
- //******************************************************************************************
- // T C a n c e l P u b l i s h e r C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TCancelPublisherCmd::ICancelPublisherCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TPublisher* itsPublisher)
-
- {
- this->ICommand(itsCmdNumber, itsDocument, NULL);
-
- fPublisher = itsPublisher;
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TCancelPublisherCmd::DoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->CancelSection(fPublisher, kCancel);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TCancelPublisherCmd::UndoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->CancelSection(fPublisher, kDontCancel);
- }
-
- //******************************************************************************************
- // T C a n c e l S u b s c r i b e r C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TCancelSubscriberCmd::ICancelSubscriberCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument,
- TView* itsView,
- TSubscriber* itsSubscriber)
-
- {
- this->ICommand(itsCmdNumber, itsDocument, itsView);
-
- fSubscriber = itsSubscriber;
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TCancelSubscriberCmd::DoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->CancelSection(fSubscriber, kCancel);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TCancelSubscriberCmd::UndoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->CancelSection(fSubscriber, kDontCancel);
- }
-
- //******************************************************************************************
- // T S e c t i o n B o r d e r C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TSectionBorderCmd::ISectionBorderCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument)
-
- {
- this->ICommand(itsCmdNumber, itsDocument, NULL);
-
- fShowSectionBorders =!((TEditionDocument *)fChangedObject)->fShowSectionBorders;
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionBorderCmd::DoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->SetSectionBorders(fShowSectionBorders, kInvalidate);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionBorderCmd::RedoIt(void)
-
- {
- this->DoIt();
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TSectionBorderCmd::UndoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->SetSectionBorders(!fShowSectionBorders, kInvalidate);
- }
-
- //******************************************************************************************
- // T S t o p A l l E d i t i o n s C m d
- //******************************************************************************************
- #pragma segment MACommandRes
-
- pascal void TStopAllEditionsCmd::IStopAllEditionsCmd(CmdNumber itsCmdNumber,
- TDocument* itsDocument)
-
- {
- this->ICommand(itsCmdNumber, itsDocument, NULL);
-
- fStopAllEditions =!((TEditionDocument *)fChangedObject)->fStopAllEditions;
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TStopAllEditionsCmd::DoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->SetStopAllEditions(fStopAllEditions);
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TStopAllEditionsCmd::RedoIt(void)
-
- {
- this->DoIt();
- }
-
- //--------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- pascal void TStopAllEditionsCmd::UndoIt(void)
-
- {
- ((TEditionDocument *)fChangedObject)->SetStopAllEditions(!fStopAllEditions);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ANonRes
-
- pascal void TSectionAdorner::Initialize(void) // override
-
- {
- inherited::Initialize();
-
- fSection = NULL;
- fBorderRgn = NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ANonRes
-
- pascal void TSectionAdorner::ISectionAdorner(IDType itsID,
- TSection* itsSection,
- RgnHandle itsBorderRgn)
-
- {
- this->IAdorner(itsID,kFreeOnDeletion);
-
- fSection = itsSection;
- fBorderRgn = itsBorderRgn;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TSectionAdorner::Free(void) // override
-
- {
- fBorderRgn = DisposeIfRgnHandle(fBorderRgn);
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TSectionAdorner::InvalidateAdorner(TView* itsView) // override
-
- {
- if ((itsView) && (fBorderRgn != NULL))
- itsView->InvalidateRgn(fBorderRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TSectionAdorner::DrawBorder(const Pattern& whichPattern)
-
- {
- // Don't use FillRgn since it ignores the penMode.
- PenNormal();
- PenMode(patXor);
- PenSize(3, 3);
- PenPat(whichPattern);
- FrameRect((*fBorderRgn)->rgnBBox); // be careful...
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ANonRes
-
- pascal void TSubscriberAdorner::ISubscriberAdorner(IDType itsID,
- TSubscriber* itsSubscriber,
- RgnHandle itsBorderRgn)
-
- {
- this->ISectionAdorner(itsID, itsSubscriber, itsBorderRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TSubscriberAdorner::DoHighlightSelection(TView* itsView,
- const VRect& ,
- HLState fromHL,
- HLState toHL)// override
-
- {
- if (itsView)
- {
- TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
- if ((itsDocument != NULL) && (itsDocument->IsBorderShown(fSection)))
- if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
- this->DrawBorder(qd.dkGray); // turning off
- else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
- this->DrawBorder(qd.dkGray); // turning on
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ANonRes
-
- pascal void TPublisherAdorner::IPublisherAdorner(IDType itsID,
- TPublisher* itsPublisher,
- RgnHandle itsBorderRgn)
-
- {
- this->ISectionAdorner(itsID, itsPublisher, itsBorderRgn);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TPublisherAdorner::DoHighlightSelection(TView* itsView,
- const VRect& ,
- HLState fromHL,
- HLState toHL)// override
-
- {
- if (itsView)
- {
- TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
- if ((itsDocument != NULL) && (itsDocument->IsBorderShown(fSection)))
- if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
- this->DrawBorder(qd.gray); // turning off
- else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
- this->DrawBorder(qd.gray); // turning on
- }
- }
-
-
-